<template>
    <div class="contioner">
        <div class="search-form divClass" v-show="headerShow" style="padding-top: 15px">
            <a-form size="small" :model="query" layout="inline">
                <a-form-item label="日期">
                    <a-date-picker  popup-container="html"  v-model="query.beginDate" :style="{ width: '180px' }" placeholder="选择日期"
                        class="bacClass" />至 <a-date-picker  popup-container="html"  v-model="query.enginDate" :style="{ width: '180px' }"
                        placeholder="选择日期" class="bacClass" />
                </a-form-item>
                <CorporateSectorCascader :configCascader="configCascader" @changeCascader="changeCascader" />
            </a-form>
            <div class="my-tool-bar" style="margin-bottom: 5px">
                <a-space>
                    <el-button type="primary" :icon="Search" @click="getList">查询</el-button>
                    <!-- <el-button pain @click="emit('takebiaoji', 0)" plain>返回主页</el-button> -->
                </a-space>
            </div>
        </div>
        <div class="my-divisders">
            <a-divider orientation="center">
                <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
                <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
            </a-divider>
        </div>

        <div style="background-color: #f0f2f5; height: 10px"></div>
        <div :style="{ height: '88%', padding: '10px', overflow: 'aout' }">
            <div style="width: 100%; height: 100%">
                  <AgGridVuesCopys :suppressCopyRowsToClipboard="true" :headerHeight="30" :rowHeight="30" rowSelection="multiple" @grid-ready="gridReady" style="height:100%"
                    :defaultColDef="defaultColDef" class='ag-theme-alpine' :rowData="tableDataList" :columnDefs="tc" :localeText="localeText1">
                </AgGridVuesCopys>
            </div>
        </div>
    </div>
</template>
    
<script lang="ts" setup>

import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
// 引入element提示
//引入封装post
import { post } from '@/api/http'
import { Search, EditPen } from '@element-plus/icons-vue'
import dayjs from 'dayjs'
import { localeText } from '@/api/aggridZw'
  const localeText1: any = ref(localeText)
const emit = defineEmits(['takebiaoji'])
const headerShow = ref<boolean>(true)

const loadings = ref(false)


const configCascader = ref<{}>({
    corporateWidth: '200px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '厂区', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
})
const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    query.planOrderCode = corporateId
}

interface Querin {
    beginDate: any
    enginDate: any
    planOrderCode: any
}
//getlist初始化接口参数
let query = reactive<Querin>({
    beginDate: dayjs().format('YYYY-MM-DD'), //当月日期
    enginDate: dayjs().format('YYYY-MM-DD'),  //当月日期
    planOrderCode: 32,
})

const tableDataList: any = ref([])
const gridOption = ref()
const gridReady = (params: any) => {
    gridOption.value = params.api
}
const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
}

const tc = [
    {
        headerName: '日期',
        field: 'planDate',
        width: 150,
        pinned: 'left'
    },
    {
        headerName: '厂部', children: [

            {
                headerName: '计划WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cJHWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'cJHNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '生产WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cSCWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'cSCNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '查布WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cCBWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'cCBNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '修补WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cXBWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'cXBNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '待入仓WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cDRKWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'cDRKNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '库存WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cKCWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'cKCNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '总WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'cSumWeight',
                        width: 100,
                        pinned: 'right',
                    },
                    {
                        headerName: '匹数',
                        field: 'cSumNum',
                        width: 100,
                        pinned: 'right',
                    }
                ],
                pinned: 'right',
            },
        ]
    },
    {
        headerName: '本集团', children: [
            {
                headerName: '计划WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bJHWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'bJHNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '生产WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bSCWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'bSCNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '查布WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bCBWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'bCBNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '修补WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bxBWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'bxBNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '待入仓WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bDRKWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'bDRKNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '库存WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bKCWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'bKCNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '总WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'bSumWeight',
                        width: 100,
                        pinned: 'right',
                    },
                    {
                        headerName: '匹数',
                        field: 'bSumNum',
                        width: 100,
                        pinned: 'right',
                    }
                ],
                pinned: 'right',
            },
        ]
    },
    {
        headerName: '外加工', children: [
            {
                headerName: '计划WIP',
                width: 300,
                children: [
                    {
                        headerName: '重量',
                        field: 'wJHWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'wJHNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '生产WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'wSCWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'wSCNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '查布WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'wCBWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'wCBNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '修补WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'wxBWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'wxBNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '待入仓WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'wDRKWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'wDRKNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '库存WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'wKCWeight',
                        width: 100
                    },
                    {
                        headerName: '匹数',
                        field: 'wKCNum',
                        width: 100
                    }
                ]
            },
            {
                headerName: '总WIP',
                children: [
                    {
                        headerName: '重量',
                        field: 'wSumWeight',
                        width: 100,
                        pinned: 'right',
                    },
                    {
                        headerName: '匹数',
                        field: 'wSumNum',
                        width: 100,
                        pinned: 'right',
                    }
                ],
                pinned: 'right',
            },
        ]
    },
]


//初始化
onMounted(async () => {
    // selectJt()
})

function selectJt() {
    loadings.value = true
    post({
        url: '/planSingle/wipRecord/getWipRecordList',
        data: {
            // "firmId": query.planOrderCode, //公司ID
            "firmId": query.planOrderCode, //公司ID
            "dateStart": query.beginDate,
            "dateEnd": query.enginDate
        }
    }).then((res: any) => {
        if (res.code == 200) {
            tableDataList.value = res.data.list
            loadings.value = false
        } else {
            Message.error(res.message)
        }
    }).finally(() => {
        loadings.value = false
    })
}
const getList = () => {
    if(query.planOrderCode){
        selectJt()
    }else{
        Message.error('厂区必选')
    }
}
</script>
<style scoped>
.contioner {
    height: 100%;
    background: #fff;
}

:deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
}

:deep(.ag-header-group-text) {
    margin: 0 auto;
}

:deep(.ag-header-group-cell) {
    border-right: 1px solid #dde2eb;
}
:deep(.ag-pinned-right-header){
    background-color:#99b5f7;
}
</style>
    